package com.oracle.Service;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.oracle.Service.impl.BookService;
import com.oracle.dao.impl.BookDao;
import com.oracle.dao.impl.OrderItemDao;
import com.oracle.pojo.Book;
import com.oracle.pojo.vo.BookVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class BookServiceImpl implements BookService {

    @Autowired
    private BookDao bookDao;

    @Autowired
    private OrderItemDao orderItemDao;

    @Override
    public int down(Integer bid) {
        return bookDao.down(bid);
    }

    @Override
    public int up(Integer bid) {
        return bookDao.up(bid);
    }

    @Override
    public String addBook(Book book) {
        String result = bookDao.addBook(book);
        if (result.equals("NO")){
            return "NO";
        }
        return "YES";
    }

    @Override
    public Page<Book> listBooks(Integer currentPage, Integer pageSize, BookVo bookVo) {
        Page<Book> pages =  PageHelper.startPage(currentPage,pageSize);
        //获得选择性查询的结果集
        bookDao.selectByExample(bookVo);

        return pages;
    }

    @Override
    public Page<Book> listBooks_All(Integer currentPage, Integer pageSize, BookVo bookVo) {
        Page<Book> pages =  PageHelper.startPage(currentPage,pageSize);
        //获得选择性查询的结果集
        bookDao.selectByExample_All(bookVo);

        return pages;
    }

    @Override
    public String updateByBid(Book book) {
        if (book==null){
            return "NO";
        }
        if (book.getBid()==null||book.getBid()==0){
            return "NO";
        }
        String result = bookDao.updateByBid(book);
        if (result.equals("NO")){
            return "NO";
        }
        return "YES";
    }

    @Override
    public List<Book> selectBooksByNumOrder() {
        return bookDao.selectBooksByNumOrder();
    }

    @Override
    public Book seleteBookbyId(Book book) {
        return bookDao.seleteBookbyId(book);
    }

    @Override
    public List<Book> selectBooksByCid(Integer cid) {
        return bookDao.selectBooksByCid(cid);
    }
}
